/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.brain.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.brain.entity.BOperRecordDetial;
import com.thinkgem.jeesite.modules.brain.service.BOperRecordDetialService;

/**
 * 操作记录明细Controller
 * @author 程展峰
 * @version 2021-09-22
 */
@Controller
@RequestMapping(value = "${adminPath}/brain/bOperRecordDetial")
public class BOperRecordDetialController extends BaseController {

	@Autowired
	private BOperRecordDetialService bOperRecordDetialService;
	
	@ModelAttribute
	public BOperRecordDetial get(@RequestParam(required=false) String id) {
		BOperRecordDetial entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = bOperRecordDetialService.get(id);
		}
		if (entity == null){
			entity = new BOperRecordDetial();
		}
		return entity;
	}
	
	@RequiresPermissions("brain:bOperRecordDetial:view")
	@RequestMapping(value = {"list", ""})
	public String list(BOperRecordDetial bOperRecordDetial, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<BOperRecordDetial> page = bOperRecordDetialService.findPage(new Page<BOperRecordDetial>(request, response), bOperRecordDetial); 
		model.addAttribute("page", page);
		return "modules/brain/bOperRecordDetialList";
	}

	@RequiresPermissions("brain:bOperRecordDetial:view")
	@RequestMapping(value = "form")
	public String form(BOperRecordDetial bOperRecordDetial, Model model) {
		model.addAttribute("bOperRecordDetial", bOperRecordDetial);
		return "modules/brain/bOperRecordDetialForm";
	}

	@RequiresPermissions("brain:bOperRecordDetial:edit")
	@RequestMapping(value = "save")
	public String save(BOperRecordDetial bOperRecordDetial, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, bOperRecordDetial)){
			return form(bOperRecordDetial, model);
		}
		bOperRecordDetialService.save(bOperRecordDetial);
		addMessage(redirectAttributes, "保存操作记录明细成功");
		return "redirect:"+Global.getAdminPath()+"/brain/bOperRecordDetial/?repage";
	}
	
	@RequiresPermissions("brain:bOperRecordDetial:edit")
	@RequestMapping(value = "delete")
	public String delete(BOperRecordDetial bOperRecordDetial, RedirectAttributes redirectAttributes) {
		bOperRecordDetialService.delete(bOperRecordDetial);
		addMessage(redirectAttributes, "删除操作记录明细成功");
		return "redirect:"+Global.getAdminPath()+"/brain/bOperRecordDetial/?repage";
	}

}